#!/bin/sh

### BEGIN INIT INFO
# Provides:          nginx
# Required-Start:    $all
# Required-Stop:     $all
# Default-Start:     2 3 4 5
# Default-Stop:      0 1 6
# Short-Description: starts the nginx web server
# Description:       starts nginx using start-stop-daemon
### END INIT INFO

PATH=/opt/web/nginx/sbin
DAEMON=/opt/web/nginx/sbin/nginx
NAME=nginx
DESC=nginx

test -x $DAEMON || exit 0

RETVAL=0

. /etc/init.d/functions

# Include nginx defaults if available
if [ -f /etc/default/nginx ] ; then
    . /etc/default/nginx
fi

start(){
  echo -n "Starting $DESC: "
  daemon $DAEMON $OPTIONS 
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && touch /var/lock/$NAME.lck
}

stop(){
  echo -n "Stopping $DESC: "
  killproc $DAEMON
  RETVAL=$?
  echo
  [ $RETVAL = 0 ] && rm -f /var/lock/$NAME.lck
}

case "$1" in
  start)
      start
      ;;
  stop)
      stop
      ;;
  restart|force-reload)
      stop
      sleep 1
      start
      ;;
  status)
      status $DAEMON
      RETVAL=$?
      ;;
  *)
    N=/etc/init.d/$NAME
    echo "Usage: $N {start|stop|restart|force-reload|status}" >&2
    exit 1
    ;;
esac

exit $RETVAL

